package com.TeacherInfoServer.mapper;

import com.TeacherInfoServer.pojo.DTO.SearchDTO.TalentTitleSearchDTO;
import com.TeacherInfoServer.pojo.entity.TalentTitle;
import com.TeacherInfoServer.pojo.vo.TalentTitleVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface TalentTitleMapper extends BaseMapper<TalentTitle> {
    List<TalentTitle> selectPageWithTeacher(Page<TalentTitle> page);

    @Select("<script>" +
            "SELECT tt.*, t.teacher_name, tl.value as titleLevel " +
            "FROM talent_title tt " +
            "LEFT JOIN teacher t ON tt.teacher_id = t.teacher_id " +
            "LEFT JOIN type_info tl ON tt.title_level_id = tl.id " +
            "<where> " +
            "<if test='search.teacherId != null and search.teacherId.trim() != \"\"'> " +
            "AND tt.teacher_id LIKE CONCAT('%', #{search.teacherId}, '%') " +
            "</if> " +
            "<if test='search.teacherName != null and search.teacherName.trim() != \"\"'> " +
            "AND t.teacher_name LIKE CONCAT('%', #{search.teacherName}, '%') " +
            "</if> " +
            "<if test='search.titleName != null and search.titleName.trim() != \"\"'> " +
            "AND tt.title_name LIKE CONCAT('%', #{search.titleName}, '%') " +
            "</if> " +
            "<if test='search.titleLevel != null and search.titleLevel.trim() != \"\"'> " +
            "AND tl.value LIKE CONCAT('%', #{search.titleLevel}, '%') " +
            "</if> " +
            "<if test='search.obtainDate != null and search.obtainDate.trim() != \"\"'> " +
            "AND tt.obtain_date LIKE CONCAT('%', #{search.obtainDate}, '%') " +
            "</if> " +
            "</where> " +
            "ORDER BY tt.teacher_id ASC, tl.value DESC" +
            "</script>")
    Page<TalentTitleVo> searchTalentTitleByPage(Page<?> page, @Param("search") TalentTitleSearchDTO search);
}
